<template>
    <div class="photoinfo-container">
        <h3>{{photoinfo.title}}</h3>
        <p>
            <span>发表时间：{{photoinfo.add_time|dateFormat}}</span>
            <span>点击次数：{{photoinfo.click}}次</span>
        </p>
        
       <vue-preview :slides="list" @close="handleClose" ></vue-preview>
        <div class="content" v-html="photoinfo.content"></div>
       <cmt-box :id="id"></cmt-box>

    </div>
</template>

<script>
// 导入评论子组件
import comment from "../subcomponent/comment.vue"



export default{
    data(){
        return{
            id:this.$route.params.id,//从路由中获取到图片id
            photoinfo:{},//图片详情
            list:[]//缩略图的数组

        }
    },
    created(){
            this.getPhotoInfo();
            this.getThumbs();
    },
    components:{
        'cmt-box':comment

    },
    methods:{
        handleClose () {
        console.log('close event')
      },
        getPhotoInfo(){      
    // 获取图片的详情
            this.$http.get('api/getimageInfo/'+this.id).then(result=>{
                if(result.body.status===0){
                this.photoinfo=result.body.message[0];
                }
                else{
                    console.log(555)
                }
            })

        },
        getThumbs(){
            this.$http.get('api/getthumimages/'+this.id).then(result=>{
               if(result.body.status===0){
                //    循环每个图片的数据，补全宽和高
                result.body.message.forEach(item=>{
                    item.w=600;
                    item.h=400;
                    item. msrc=item.src;
                });
                this.list=result.body.message
                }
                else{
                    console.log(555)
                } 
            })
        }
    }
}


</script>
<style>
.my-gallery img{width:60px; height:60px;}
.my-gallery figure{display:inline-block; margin:10px}


</style>